/**
 * 
 */
package com.base.myproject.client.busi.service.assessment;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Administrator
 *2010-1-29
 */
public class Assessment_rule2 extends BaseJDBCPanel{
	BaseGrid<BusiObject> Mgrid ;
	BaseGrid<BusiObject> Ggrid ;
	BaseStore<BusiObject> mstore;
	BaseStore<BusiObject> gstore;
	public Assessment_rule2()
	{
		init();
	}
	public void init()
	{
		initMstore();
		initGstroe();
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
		centerData.setMargins(new Margins(5, 5, 0, 0));
		this.add(initWeiget(), centerData);
		
		registerMainStore(mstore);
		registerStore(mstore);
		registerStore(gstore);
	}
	public ContentPanel initWeiget() {
	
		ContentPanel panel = new ContentPanel();
		panel.setHeaderVisible(false);

		panel.setAutoHeight(true);
		panel.setAutoWidth(true);
		
		HorizontalPanel hpanel = new HorizontalPanel();
		hpanel.add(createMGrid());
		hpanel.add(createGGrid());
		hpanel.setSpacing(20);
		panel.add(hpanel);
		return panel;
	}
	void initMstore()
	{
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.addField("name");
		type.addField("icode");
		
		
		StoreInfo info = new StoreInfo();
		
		info.setTablename("assessment_rule2m");
		info.setNeedAllRow("no");
		info.setForcenolimit("true");
		
		info.setKeyname(new String[]{"icode"});
		info.setSql("select * from assessment_rule2m");
	
		mstore = new BaseStore<BusiObject>(type, info,true);
		
	}
	void initGstroe()
	{
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.addField("area");

		type.addField("method");
		type.addField("upicode");
		
		StoreInfo info = new StoreInfo();
		
		info.setTablename("assessment_rule2g");
		info.setNeedAllRow("no");
		info.setForcenolimit("true");
		
		info.setKeyname(new String[]{"icode"});
		info.setSql("select * from assessment_rule2g where upicode='{icode}'");
		info.setParent(mstore);
		info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "upicode" });// 关联主表字段
		
		gstore = new BaseStore<BusiObject>(type, info,true);
		
	}
	
	Widget createMGrid()
	{
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
	
	
		ColumnConfig c1 = new ColumnConfig("name", "名称", 100);
		TextField<String> c1text = new TextField<String>();
		c1.setEditor(new CellEditor(c1text));
		
		columns.add(c1);
		
		ColumnModel cm = new ColumnModel(columns);
		cbs.setSelectionMode(SelectionMode.MULTI);
		Mgrid = new BaseGrid<BusiObject>(mstore, cm,true,true,null);
		Mgrid.setSelectionModel(cbs);

		Mgrid.setSize(250,300);
		Mgrid.getView().setForceFit(true);
		return Mgrid;
		//return Mgrid;
		
	}
	
	Widget createGGrid()
	{
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
	
//		columns.add(new ColumnConfig("area", "区间", 50));
//		columns.add(new ColumnConfig("method", "提成", 50));
		
		ColumnConfig c1 = new ColumnConfig("area", "区间", 50);
		TextField<String> c1text = new TextField<String>();
		c1.setEditor(new CellEditor(c1text));
		
		ColumnConfig c2 = new ColumnConfig("method", "提成", 50);
		NumberField c2_n = new NumberField();
		c2.setEditor(new CellEditor(c2_n));
		
		
		columns.add(c1);
		columns.add(c2);
		
		ColumnModel cm = new ColumnModel(columns);
		cbs.setSelectionMode(SelectionMode.MULTI);
		Ggrid = new BaseGrid<BusiObject>(gstore, cm,true,true,null);
		Ggrid.setSelectionModel(cbs);

		Ggrid.setSize(250,300);
		Ggrid.getView().setForceFit(true);
		return Ggrid;
	
		
	}
}
